package com.baidu.dao;

import com.baidu.pojo.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface AdministratorMapper {

    //管理员登录
    @Select("SELECT * FROM users WHERE uname=#{uname} AND upassword=#{upassword} and ustate=0")
    public User login(User user);

    @Select("select * from users")
    public List<User> test();

    //添加用户
    @Insert("INSERT INTO users (uname,upassword,utime,ucount,uemil,pid,ustate) VALUES(#{uname},#{upassword},#{utime},#{ucount},#{uemil},#{pid},0)")
    public void addUser(User user);

    //根据id修改用户信息
    @Update("UPDATE users SET uname=#{uname},upassword=#{upassword},utime=#{utime},ucount=#{ucount},uemil=#{uemil},pid=#{pid}\n" +
            "WHERE uid=#{uid}")
    public void updateUserById(User user);

    //根据id删除用户信息
    @Update("UPDATE users SET ustate=1 WHERE uid=#{uid}")
    public void deleteUserById(Integer uid);

    //根据用户名查询指定的用户信息
    @Select("SELECT * FROM users WHERE uname=#{uname}")
    public User getUserByName(String uname);



    //查询所有用户信息
    public List<User> getAllUser();

    //分页查询所有用户信息,以及关联的角色信息 第一个参数表示起始位置，第二个参数表示页面容量
    public List<User> getByPage(@Param("start")Integer start, @Param("pageSize")Integer pageSize);

    //分页查询总记录数
    @Select("select COUNT(*) from users where ustate!=1")
    public int count();

    //根据id查询指定的用户信息
    public  User getUserById(Integer uid);


}
